﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Configuration;

namespace GrayParrot.Web.Security.Configuration
{
    public static class SecuritySettingsExtension
    {
        /// <summary>
        /// Gets the login URL.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static string GetLoginUrl(this IConfigurationManagerHelper value)
        {
            string retValue = null;

            SecuritySettings cfg = SecuritySettings.GetConfiguration(@"GrayParrotGroup/SecuritySettings");
            retValue = cfg.LoginUrl;

            return retValue;
        }

        /// <summary>
        /// Gets the user name without domain.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool GetUserNameWithoutDomain(this IConfigurationManagerHelper value)
        {
            bool retValue = false;

            SecuritySettings cfg = SecuritySettings.GetConfiguration(@"GrayParrotGroup/SecuritySettings");
            retValue = cfg.UserNameWithoutDomain;

            return retValue;
        }

        /// <summary>
        /// Gets the no login required.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool GetNoLoginRequired(this IConfigurationManagerHelper value)
        {
            bool retValue = false;

            SecuritySettings cfg = SecuritySettings.GetConfiguration(@"GrayParrotGroup/SecuritySettings");
            retValue = cfg.NoLoginRequired;

            return retValue;
        }

        /// <summary>
        /// Gets the Asp.Net Membership application name...
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <remarks>
        /// This is the name of the Application defined for ASP.NET Membership.
        /// The default Application Name is BO...
        /// </remarks>
        public static string GetApplicationName(this IConfigurationManagerHelper value)
        {
            string retValue = "BO";

            SecuritySettings cfg = SecuritySettings.GetConfiguration(@"GrayParrotGroup/SecuritySettings");
            retValue = cfg.ApplicationName;

            return retValue;
        }

        /// <summary>
        /// Gets the name of the connection string needed for connect to Membership database...
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <remarks>
        /// The default name for the connection string is 'SecurityAuth'...
        /// </remarks>
        public static string GetConnectionStringName(this IConfigurationManagerHelper value)
        {
            string retValue = "SecurityAuth";

            SecuritySettings cfg = SecuritySettings.GetConfiguration(@"GrayParrotGroup/SecuritySettings");
            retValue = cfg.ConnectionStringName;

            return retValue;
        }
    }
}
